home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_337 / cmanual / menus.lzh / Menus / Example7.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  10KB  |  314 lines

  1. /* Example7                                                              */
  2. /* This program opens a normal window to which we connect a menu strip.  */
  3. /* The menu consists of one small action item with two images.           */
  4.  
  5.  
  6.  
  7. #include <intuition/intuition.h>
  8.  
  9.  
  10.  
  11. struct IntuitionBase *IntuitionBase;
  12.  
  13.  
  14.  
  15. /*************************************************************************/
  16. /*                        F A C E   S L E E P I N G                      */
  17. /*************************************************************************/
  18.  
  19. USHORT chip face_sleeping_data[]=
  20. {
  21.   0x7FFF,0xFC00, /* Bitplane ZERO */
  22.   0xFE10,0xFE00,
  23.   0xF9D7,0x3E00,
  24.   0xE7D7,0xCE00,
  25.   0xDFD7,0xF600,
  26.   0xDF93,0xF600,
  27.   0xC054,0x0600,
  28.   0xDFD7,0xF600,
  29.   0xC010,0x0600,
  30.   0xFFFF,0xFE00,
  31.   0x7FFF,0xFC00,
  32.     
  33.   0x7FFF,0xFC00, /* Bitplane ONE */
  34.   0xFFFF,0xFE00,
  35.   0xFFFF,0xFE00,
  36.   0xFFFF,0xFE00,
  37.   0xFFFF,0xFE00,
  38.   0xFFFF,0xFE00,
  39.   0xFFBB,0xFE00,
  40.   0xE038,0x0E00,
  41.   0xFFFF,0xFE00,
  42.   0xFFFF,0xFE00,
  43.   0x7FFF,0xFC00
  44. };
  45.  
  46. /* Image structure for the sleeping face: */
  47. struct Image face_sleeping=
  48. {
  49.   0,          /* LeftEdge, 0 pixels out. */
  50.   0,          /* TopEdge, 0 pixels down. */
  51.   23,         /* Width, 23 pixels wide. */
  52.   11,         /* Height, 11 lines heigh. */
  53.   2,          /* Depth, two Bitplanes. */
  54.   face_sleeping_data, /* ImageData, pointer to the image data. */
  55.   0x3,        /* PlanePick, affect Bitplane zero and one. */
  56.   0x0,        /* PlaneOnOff, do not bother about any Bitplanes. */
  57.   NULL        /* NextImage, no Image structure connected to this one. */
  58. };
  59.  
  60.  
  61.  
  62. /*************************************************************************/
  63. /*                          F A C E   A W A K E                          */
  64. /*************************************************************************/
  65.  
  66. USHORT chip face_awake_data[]=
  67. {
  68.   0x7FFF,0xFC00, /* Bitplane ZERO */
  69.   0xFE10,0xFE00,
  70.   0xF9D7,0x3E00,
  71.   0xE7D7,0xCE00,
  72.   0xDFD7,0xF600,
  73.   0xDE10,0xF600,
  74.   0xDC10,0x7600,
  75.   0xDC10,0x7600,
  76.   0xC010,0x0600,
  77.   0xFFFF,0xFE00,
  78.   0x7FFF,0xFC00,
  79.  
  80.   0x7FFF,0xFC00, /* Bitplane ONE */
  81.   0xFFFF,0xFE00,
  82.   0xFE38,0xFE00,
  83.   0xF838,0x3E00,
  84.   0xE038,0x0E00,
  85.   0xE1FF,0x0E00,
  86.   0xE3FF,0x8E00,
  87.   0xE3FF,0x8E00,
  88.   0xFFFF,0xFE00,
  89.   0xFFFF,0xFE00,
  90.   0x7FFF,0xFC00
  91. };
  92.  
  93. /* Image structure for the awake face: */
  94. struct Image face_awake=
  95. {
  96.   0,          /* LeftEdge, 0 pixels out. */
  97.   0,          /* TopEdge, 0 pixels down. */
  98.   23,         /* Width, 23 pixels wide. */
  99.   11,         /* Height, 11 lines heigh. */
  100.   2,          /* Depth, two Bitplanes. */
  101.   face_awake_data, /* ImageData, pointer to the image data. */
  102.   0x3,        /* PlanePick, affect Bitplane zero and one. */
  103.   0x0,        /* PlaneOnOff, do not bother about any Bitplanes. */
  104.   NULL        /* NextImage, no Image structure connected to this one. */
  105. };
  106.  
  107.  
  108.  
  109. /*************************************************************************/
  110. /*                           M E N U   I T E M                           */
  111. /*************************************************************************/
  112.  
  113. /* The one and only MenuItem structure: */
  114. struct MenuItem my_item=
  115. {
  116.   NULL,            /* NextItem, this is the one and only item. */
  117.   0,               /* LeftEdge, 0 pixels out. */
  118.   0,               /* TopEdge, 0 lines down. */
  119.   50,              /* Width, 50 pixels wide. */
  120.   11,              /* Height, 11 lines high. */
  121.   ITEMENABLED|     /* Flags, this item will be enabled. */
  122.                    /*        render this item with an Image. */
  123.                    /*        (ITEMTEXT is not set.) */
  124.                    /*        it is an action item. */
  125.                    /*        (CHECKIT is not set.) */
  126.   HIGHIMAGE,       /*        display an alternative Image when highl. */
  127.   0x00000000,      /* MutualExclude, no mutualexclude. */
  128.   (APTR) &face_sleeping, /* ItemFill, pointer to the image. */
  129.   (APTR) &face_awake,    /* SelectFill, pointer to the alternative image. */
  130.   0,               /* Command, no command-key sequence. */
  131.   NULL,            /* SubItem, no subitem list. */
  132.   MENUNULL,        /* NextSelect, no items selected. */
  133. };
  134.  
  135.  
  136.  
  137. /*************************************************************************/
  138. /*                              M E N U                                  */
  139. /*************************************************************************/
  140.  
  141. /* The Menu structure for the first (and only) menu: */
  142. struct Menu my_menu=
  143. {
  144.   NULL,        /* NextMenu, no more menu structures. */
  145.   0,           /* LeftEdge, left corner. */
  146.   0,           /* TopEdge, for the moment ignored by Intuition. */
  147.   50,          /* Width, 50 pixels wide. */
  148.   0,           /* Height, for the moment ignored by Intuition. */
  149.   MENUENABLED, /* Flags, this menu will be enabled. */
  150.   "Face",      /* MenuName, the string. */
  151.   &my_item     /* FirstItem, pointer to the first item in the list. */
  152. };
  153.  
  154.  
  155.  
  156. /* Declare a pointer to a Window structure: */ 
  157. struct Window *my_window;
  158.  
  159. /* Declare and initialize your NewWindow structure: */
  160. struct NewWindow my_new_window=
  161. {
  162.   50,            /* LeftEdge    x position of the window. */
  163.   25,            /* TopEdge     y positio of the window. */
  164.   200,           /* Width       200 pixels wide. */
  165.   100,           /* Height      100 lines high. */
  166.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  167.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  168.   CLOSEWINDOW|   /* IDCMPFlags  The window will give us a message if the */
  169.                  /*             user has selected the Close window gad. */
  170.   MENUPICK,
  171.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  172.   WINDOWCLOSE|   /*             Close Gadget. */
  173.   WINDOWDRAG|    /*             Drag gadget. */
  174.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  175.   WINDOWSIZING|  /*             Sizing Gadget. */
  176.   ACTIVATE,      /*             The window should be Active when opened. */
  177.   NULL,          /* FirstGadget No Custom gadgets. */
  178.   NULL,          /* CheckMark   Use Intuition's default checkmark. */
  179.   "Person",      /* Title       Title of the window. */
  180.   NULL,          /* Screen      Connected to the Workbench Screen. */
  181.   NULL,          /* BitMap      No Custom BitMap. */
  182.   80,            /* MinWidth    We will not allow the window to become */
  183.   30,            /* MinHeight   smaller than 80 x 30, and not bigger */
  184.   300,           /* MaxWidth    than 300 x 200. */
  185.   200,           /* MaxHeight */
  186.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  187. };
  188.  
  189.  
  190.  
  191. main()
  192. {
  193.   /* Boolean variable used for the while loop: */
  194.   BOOL close_me;
  195.  
  196.   /* Declare a variable in which we will store the IDCMP flag: */
  197.   ULONG class;
  198.   
  199.   /* If we recieve a MENUPICK event, the Code field of the message */
  200.   /* structure will contain the menu number of the first selected item. */
  201.   /* Declare a variable to store the Code value in, and an extra menu */
  202.   /* number variable: */
  203.   USHORT code, menu_number;
  204.   
  205.   /* Declare a MenuItem pointer: */
  206.   struct MenuItem *item;
  207.   
  208.   /* Declare a pointer to an IntuiMessage structure: */
  209.   struct IntuiMessage *my_message;
  210.  
  211.  
  212.  
  213.   /* Before we can use Intuition we need to open the Intuition Library: */
  214.   IntuitionBase = (struct IntuitionBase *)
  215.     OpenLibrary( "intuition.library", 0 );
  216.   
  217.   if( IntuitionBase == NULL )
  218.     exit(); /* Could NOT open the Intuition Library! */
  219.  
  220.  
  221.  
  222.   /* We will now try to open the window: */
  223.   my_window = (struct Window *) OpenWindow( &my_new_window );
  224.   
  225.   /* Have we opened the window succesfully? */
  226.   if(my_window == NULL)
  227.   {
  228.     /* Could NOT open the Window! */
  229.     
  230.     /* Close the Intuition Library since we have opened it: */
  231.     CloseLibrary( IntuitionBase );
  232.  
  233.     exit();  
  234.   }
  235.  
  236.  
  237.  
  238.   /* We have opened the window, and everything seems to be OK. */
  239.  
  240.  
  241.  
  242.   SetMenuStrip( my_window, &my_menu );
  243.   printf("Menustrip connected to window!\n");
  244.  
  245.  
  246.   close_me = FALSE;
  247.  
  248.   /* Stay in the while loop until the user has selected the Close window */
  249.   /* gadget: */
  250.   while( close_me == FALSE )
  251.   {
  252.     /* Wait until we have recieved a message: */
  253.     Wait( 1 << my_window->UserPort->mp_SigBit );
  254.  
  255.     /* As long as we collect messages sucessfully we stay in the loop: */
  256.     while(my_message=(struct IntuiMessage *) GetMsg( my_window->UserPort ))
  257.     {
  258.       /* After we have collected the message we can read it, and save any */
  259.       /* important values which we maybe want to check later: */
  260.       class = my_message->Class;
  261.       code = my_message->Code;
  262.  
  263.  
  264.       /* After we have read it we reply as fast as possible: */
  265.       /* REMEMBER! Do never try to read a message after you have replied! */
  266.       /* Some other process has maybe changed it. */
  267.       ReplyMsg( my_message );
  268.  
  269.       /* Check which IDCMP flag was sent: */
  270.       if( class == CLOSEWINDOW )
  271.         close_me=TRUE; /* The user selected the Close window gadget! */  
  272.  
  273.       if(class == MENUPICK)
  274.       {
  275.         printf("\nMenu pick!\n");
  276.         menu_number = code;
  277.         
  278.         while( menu_number != MENUNULL )
  279.         {
  280.           /* Get the address of the item: */
  281.           item = (struct MenuItem *) ItemAddress( &my_menu, menu_number );
  282.  
  283.  
  284.           /* Print out the menu number plus etc: */
  285.           printf("menu_number= %d\n", menu_number );
  286.           printf("MENUNUM = %d\n", MENUNUM(menu_number) );
  287.           printf("ITEMNUM = %d\n", ITEMNUM(menu_number) );
  288.           printf("SUBNUM  = %d\n", SUBNUM(menu_number) );
  289.  
  290.  
  291.           /* Get the following item's menu number: */
  292.           menu_number = item->NextSelect;
  293.         }
  294.       }
  295.     }
  296.   }
  297.  
  298.  
  299.  
  300.   printf("Menustrip removed from window!\n");
  301.   ClearMenuStrip( my_window );
  302.  
  303.  
  304.  
  305.   /* Close the window: */
  306.   CloseWindow( my_window );
  307.  
  308.  
  309.  
  310.   /* Close the Intuition Library since we have opened it: */
  311.   CloseLibrary( IntuitionBase );
  312.   
  313.   /* THE END */
  314. }